<?php
/**
 * 入口文件应用管理类
 * 
 * Copyright (c) 2014~2019 https://desion.net All rights reserved.
 * Author: 阿林 QQ:120867629 <linhong00@gmail.com>
 */
declare (strict_types = 1);
namespace app\controller;
use dsphp\Controller;
use app\controller\Template;

class Common extends Controller
{
    // 初始化
    protected function init(){}
    protected function moduleInit(){}


    protected function initialize()
    {
        //
    }   

    /**
     * 上传文件
     *
     * @param mixed $name   名称 false 为自动生成 空为原名 
     * @param string $path  空为年月
     * @param string $ext   
     * @return void
     */
    public function upload($name = false, string $path = '', string $ext = '')
    {
        $file = $http->files();
        if (empty($file)) {
            return false;
        }

        $upPath = $this->app->getAppPath();
        $upload = $this->app->make('upload', [$upPath]);
        $result = $upload->data($file)
                    ->setSaveName($name)
                    ->setSavePath($path)
                    ->setSaveExt($ext)
                    ->move();

        return $result;
    }

    /**
     * 初始化模板类
     */
    private function _tplInit()
    {
        if ($this->tpl === false) {
            return ;
        }

        $config = $this->app->getConfig('template');
        $config['debug'] = $this->config['app_debug'];

        $themePath  = $this->app->getAppPath();
        $themePath .= 'themes/';
        $config['theme_path'] = $themePath;

        $cache   = $config['cache_path'] ?: 'theme';
        $runtime = $this->app->getRuntimePath();
        $config['cache_path'] = $runtime . $cache . DIRECTORY_SEPARATOR;

        $template   = "app\\controller\\Template";
        $this->tpl  = $this->app->make($template, [$config]);
    }
}
